package com.hellohoper.script.config.engine.container;

import com.google.common.collect.Maps;
import org.apache.commons.lang.StringUtils;

import java.util.Map;

/**
 * Groovy脚本容器
 * Created by hk on 17/8/15.
 */
public class GroovyScriptContainer implements ScriptContainer {

    // 脚本容器
    private Map<String, String> localGroovyScriptContainer = Maps.newHashMap();

    @Override
    public void addScript(String appName, String scriptName, String scriptContent) {

        if (StringUtils.isEmpty(appName) || StringUtils.isEmpty(scriptName) || StringUtils.isEmpty(scriptContent)) {
            return;
        }
        String key = appName + scriptName;
        localGroovyScriptContainer.put(key, scriptContent);
    }

    @Override
    public void removeScript(String appName, String scriptName) {
        if (StringUtils.isEmpty(appName) || StringUtils.isEmpty(scriptName)) {
            return;
        }
        String key = appName + scriptName;
        if (localGroovyScriptContainer.containsKey(key)) {
            localGroovyScriptContainer.remove(key);
        }

    }

    @Override
    public String getScript(String appName, String scriptName) {
        if (StringUtils.isEmpty(appName) || StringUtils.isEmpty(scriptName)) {
            return null;
        }
        String key = appName + scriptName;
        if (localGroovyScriptContainer.containsKey(key)) {
            return localGroovyScriptContainer.get(key);
        }
        return null;
    }
}
